import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store/index'
import http from "../utils/httpRequest";




Vue.use(VueRouter)
/**
 * 全局路由
 * @type {VueRouter}
 */

const routers = [
    {path:'/login',component:()=>import('@/views/common/login'),meta:{title: '登录'}},
    {
        path: '/',
        name: 'home',
        meta:{
            title: '入口,布局',
        },
        component:() => import('@/views/Home'),


        children:[

            /**
             * 首页
             */
            {
                path: '/index',
                name: 'index',
                component:()=>import('@/views/sys/index')
                // component: (resolve) => require(['@/views/sys/index'], resolve)
            },
            /**
             * 系统管理============================================================
             */
            {
                path: '/sysMenu',
                name: '',
                meta:{
                    title: '菜单管理'
                },
                component:()=>import('@/views/sys/menu')
            },
            {
                path: '/authManage',
                name: '',
                meta:{
                    title: '菜单管理'
                },
                component:()=>import('@/views/sys/auth')
            },
            {
                path: '/admin',
                name: '',
                meta:{
                    title: '管理员'
                },
                component:()=>import('@/views/sys/user')
            },
            {
                path: '/audit',
                name: '',
                meta:{
                    title: '商品审核'
                },
                component:()=>import('@/views/sys/audit')
            },
            {
                path: '/auditLog',
                name: '',
                meta:{
                    title: '审核日志'
                },
                component:()=>import('@/views/sys/auditLog')
            },
            {
                path: '/log',
                name: '',
                meta:{
                    title: '日志'
                },
                component:()=>import('@/views/sys/loginlog')
            },
            /**
             * 商城系统==========================================================
             */
            {
                path: '/shopCoupon',
                name: '',
                meta:{
                    title: '商品管理'
                },
                component:()=>import('@/views/product/coupon')
            },
            {
                path: '/category',
                name: '',
                meta:{
                    title: '商品分类'
                },
                component:()=>import('@/views/product/category')
            },
            {
                path: '/clothing',
                name: '',
                meta:{
                    title: '服装服饰'
                },
                component:()=>import('@/views/product/clothing')
            },
            {
                path: '/electronic',
                name: '',
                meta:{
                    title: '数码产品'
                },
                component:()=>import('@/views/product/electronic')
            },
            //重构后的数据，全局表
            {
                path: '/spu',
                name: '',
                meta:{
                    title: '所有商品'
                },
                component:()=>import('@/views/product/spu')
            },
            {
                path: '/addShop',
                name: '',
                meta:{
                    title: '商品添加'
                },
                component:()=>import('@/views/product/add-shop')
            },

            /**
             * 会员模块*************************************************************************************8
             */
            {
                path: '/member',
                name: '',
                meta:{
                    title: '会员管理'
                },
                component:()=>import('@/views/member/member')
            },
            {
                path: '/shopCart',
                name: '',
                meta:{
                    title: '购物车'
                },
                component:()=>import('@/views/member/cart')
            },
            /**
             * ***************************订单模块
             */
            {
                path: '/order',
                name: '',
                meta:{
                    title: '订单管理'
                },
                component:()=>import('@/views/order/order')
            },
            {
                path: '/shipLog',
                name: '',
                meta:{
                    title: '发货日志'
                },
                component:()=>import('@/views/order/shipLog')
            },
            {
                path: '/receiptLog',
                name: '',
                meta:{
                    title: '发货日志'
                },
                component:()=>import('@/views/order/receiptLog')
            },
            {
                path: '/subLog',
                name: '',
                meta:{
                    title: '发货日志'
                },
                component:()=>import('@/views/order/subLog')
            },

            /**
             * ***********************************数据分析模块******************************
             */
            {
                path: '/productData',
                name: '',
                meta:{
                    title: '商品数据'
                },
                component:()=>import('@/views/data/product-data')
            },
            {
                path: '/memberData',
                name: '',
                meta:{
                    title: '商品数据'
                },
                component:()=>import('@/views/data/member-data')
            },




        ]
    }
]





const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes:routers
})


/**
 * 路由守卫
 */
router.beforeEach((to, from, next) => {
    if (to.path === '/login'){
        return next()
    }
    if (sessionStorage.getItem('roleId')==null){
        return next('/login')
    }

    next()

})





export default router
